package constructor.adaptor.dispacther;

import java.util.ArrayList;
import java.util.List;

public class Dispatcher {

    static List<ParentAdaptor> parentAdaptors;

    static {
        parentAdaptors = new ArrayList<>();
        parentAdaptors.add(new HttpAdaptor());
        parentAdaptors.add(new PersonAdaptor());
    }

    public void doDispatcher() {
        Controller handler = new PersonController();
//        PersonController personController = new PersonController();
        ParentAdaptor adaptor = getAdaptor(handler);
        if (adaptor != null) {
            adaptor.hanldle(handler);
        }
    }

    private ParentAdaptor getAdaptor(Object handler) {
        for (ParentAdaptor parentAdaptor : parentAdaptors) {
            if (parentAdaptor.supports(handler)) {
                return parentAdaptor;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        Dispatcher dispatcher = new Dispatcher();
        dispatcher.doDispatcher();
    }


}
